<?php
/* @var $this SurveyUserController */
/* @var $model SurveyUser */

$this->breadcrumbs=array(
	Yii::t('base','Manually Draw')=>array('admin'),
	Yii::t('base','Manage'),
);

Yii::app()->clientScript->registerScript('search', "
$('#search-form form').submit(function(){
	$('#event-customer-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");

$userId = $_GET['user_id'];
$event_code = $_GET['event_code'];
$event_id = $_GET['event_id'];
?>
<input type="hidden" name="event_code" id="event_code" value="<?php echo $event_code;?>" />
<input type="hidden" name="user_id" id="user_id" value="<?php echo $userId;?>" />
<input type="hidden" name="event_id" id="event_id" value="<?php echo $event_id;?>" />

<script type="text/javascript">
function GetCheckbox(){
	var code = $('#event_code').val();
	var userId = $('#user_id').val();
	var event_id = $('#event_id').val();
    var data=new Array();
    $("input:checkbox[name='customer_id[]']").each(function (){
        
            if($(this).attr("checked")=="checked"){
                    data.push($(this).val());
            }
    });
    if(data.length > 0){
            $.post("<?php echo Yii::app()->createUrl('EventCustomer/confirmPrizeWinning'); ?>",{'customer_id[]':data,'code':code,'event_id':event_id}, 
            function (data) {
                var dataArr = data.split(",");
                
                    if (dataArr[0]=='ok') {
                        alert('<?php echo Yii::t('base', 'Lottery Success!');?>');
  					location.href ="../eventCustomer/lottery?user_id="+userId+"&event_code="+dataArr[1];
                  }
            });
    }else{
            alert('<?php echo Yii::t('base', 'Please select the options you want to draw!');?>');
    }
}
</script>

<h1><?php echo Yii::t('base','Manage');echo Yii::t('base','Manually Draw');?> </h1>

<?php 
	
	$sql="select count(*) as unm from zy_event_customer where partner_id='".$userId."' and winning_status = 1 and event_code='".$event_code."'";
	$rs = yii::app()->db->createCommand($sql)->queryAll();
	
	$sqlpeopleunm ="select count(*) as peopleunm from zy_event_customer where partner_id='".$userId."' and winning_status = 0 and event_code='".$event_code."'";
	$rss = yii::app()->db->createCommand($sqlpeopleunm)->queryAll();
	
	$activitySql = "select prize_qty from zy_event where event_code='".$event_code."'";
	$activityRs = yii::app()->db->createCommand($activitySql)->queryAll();
	
?>
<h2>
<p class="red"><?php echo Yii::t('base', 'The number of prizes:');  echo $activityRs[0]['prize_qty'];?>,<?php echo Yii::t('base', 'Currently winning numbers:'); echo $rs[0]['unm'];?>,<?php echo Yii::t('base', 'Subject lottery numbers:'); echo $rss[0]['peopleunm']; ?></p>
</h2>

<?php echo Yii::t('base','<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>');?>

<div class="row-fluid">
	<div class="span12">
    	<div class="box gradient">
        	<div class="title">
           	<?php echo CHtml::link(Yii::t('common','Advanced Search'),'#collapseOne',array('class'=>'search-button accordion-toggle collapsed btn btn-mini zyBtn03','data-toggle'=>'collapse','data-parent'=>'#accordion2')); ?>
             <?php 
				$level = yii::app()->user->level();
				if($level == 9||$level==1){
			?>
		<a class="btn btn-small create" title="<?php echo Yii::t('base','Confirm Prize Winning');?>" 
			href="javascript:void(0);" onclick="GetCheckbox();">
		<?php echo Yii::t('base','Confirm Prize Winning');?></a>

		<?php }?>              <h3> <i class="icon-sitemap"></i> <span><?php echo Yii::t('EventCustomer','Manage Event Customers') ?></span> </h3>
            </div>
            
			<div class="content"> 
			
 			<!--search start-->
 			
              <?php $this->renderPartial('_search',array(
					'model'=>$model,
				)); ?>
              
            <!--search over-->
            
            <!-- table start -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'event-customer-grid',
	'dataProvider'=>$model->search(),
	'itemsCssClass'=>'responsive table table-striped table-bordered',
	'pager'=>array('class'=>'CLinkPager','hiddenPageCssClass'=>'','firstPageCssClass'=>'first paginate_button','firstPageLabel'=>'First','prevPageLabel' => 'Previous','nextPageLabel' => 'Next','lastPageLabel'=>'Last','htmlOptions'=>array('class'=>'dataTables_paginate paging_full_numbers"'),'header'=>""),
	'pagerCssClass'=>'pagination',
	'cssFile'=>false,
	'template'=>'{items}{summary}{pager}',
	'summaryText'=>'Default Pagination',
	'columns'=>array(
		array(
				'id'=>'customer_id',
				'class'=>'CCheckBoxColumn',
				'selectableRows' => '50',
		),
		array('name'=>'partner_id','value'=>'User::model()->findByPk($data->partner_id)->user_name'),
		//array('name'=>'activety_code','value'=>'GiftPassword::model()->getActivityName($data->activety_code)'),
		'firstname',
		'lastname',
		'emailaddress',
		'mobile',
		array('name'=>'award_address','value'=>'Event::model()->getAddressList($data->award_address)','visible'=>Yii::app()->user->level() == 9),
		array('name'=>'award_address','value'=>'Event::model()->getAddressLists($data->award_address,$data->partner_id)','visible'=>Yii::app()->user->level() == 1),
		//array('name'=>'award_address_id','value'=>'Event::model()->getAddressList($data->award_address_id)','visible'=>Yii::app()->user->level() == 9),
		//array('name'=>'award_address_id','value'=>'Event::model()->getAddressLists($data->award_address_id,$data->partner_id)','visible'=>Yii::app()->user->level() == 1),
		array('name'=>'award_address_id','headerHtmlOptions'=>array('style'=>'width:10%'),'visible'=>Yii::app()->user->level() == 1 || Yii::app()->user->level() == 9),
		array('name'=>'winning_status','value'=>'EventCustomer::model()->switchStatus($data->winning_status)'),
		array('name'=>'sms_status','value'=>'EventCustomer::model()->SmsSwitchStatus($data->sms_status)'),
	),
)); ?>
